fix: correct return type annotation for find_one_and_* methods to include None
#2615
+51
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
find_one_and_update's existing type hint makes the false claim that the method returns a_DocumentType. However, the docstring (correctly) tells us that the method "Returns ``None`` if no document matches the filter."The same is true of other
find_one_and_*methods.Changes in this PR
This PR corrects the type hint of the
find_one_and_*methods to indicate that the function may return either_DocumentTypeorNone(rather than just_DocumentType).I've also updated the docstrings for the methods to make this behavior clearer.
Depending on what you consider to be the "surface area" of your library's API, this might be considered a breaking change.
I can't think of any code that would break at runtime (since the PR doesn't change runtime behavior), but it's possible someone has written code like the following. This PR would cause the
assert_typeto fail at "type checking time".Testing Plan
This change isn't changing any runtime behavior, so I'm not sure how I'd test it. I'm open to suggestions for how to test this if you have any.
Screenshots (optional)
N/A
Checklist
Checklist for Author
Checklist for Reviewer {@primary_reviewer}
Focus Areas for Reviewer (optional)